/*******************************************************************************
 * Level Master 2000
 * Copyright (C) 2010 Christian Herzog
 * For more information see http://code.google.com/p/levelmaster2000/
 *
 * This file is licensed under the terms of the MIT license, see
 * http://www.opensource.org/licenses/mit-license.php for further information.
 ******************************************************************************/

#include "CreateComponentCommand.h"

#include <QUndoCommand>

#include "../EntityExplorer.h"
#include "../Group.h"
#include "../LevelMaster2000.h"

CreateComponentCommand::CreateComponentCommand( EntityExplorer* entityExplorer,
                                                QString entityName,
                                                QString componentName,
                                                QString className,
                                                QUndoCommand *parent )
                                                    : QUndoCommand( parent ),
                                                    entityExplorer( entityExplorer ),
                                                    entityName( entityName ),
                                                    componentName( componentName ),
                                                    className( className )
{
    init();
}

void CreateComponentCommand::init()
{
    setText( "Create Component \"#" + entityName + "." + componentName + "\"" );
}

void CreateComponentCommand::undo()
{
    LevelMaster2000::DISALLOW_NEW_COMMAND++;
    entityExplorer->deleteComponent( entityName, componentName );
    LevelMaster2000::DISALLOW_NEW_COMMAND--;
}

void CreateComponentCommand::redo()
{
    if( !LevelMaster2000::DISALLOW_NEW_COMMAND )
    {
        LevelMaster2000::DISALLOW_NEW_COMMAND++;
        entityExplorer->createComponent( componentName, className );
        LevelMaster2000::DISALLOW_NEW_COMMAND--;
    }
}
